<?php
namespace App\Http\Controllers\H5;

use App\Http\Controllers\Controller;
use App\Service\H5\IndexService;
use Illuminate\Http\Request;

class IndexController extends Controller
{
    //获取页面
    public function index(Request $request)
    {
        $code = $request->post('code', '');
        if (!$code) {
            return $this->toJson(-2, '这是空码');
        }
        $res = IndexService::index($code);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //详情
    public function one(Request $request)
    {
        $code = $request->post('code', '');
        if (!$code) {
            return $this->toJson(-2, '这是空码');
        }
        $res = IndexService::one($code);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //广告已读
    public function adRead(Request $request)
    {
        $ad_id = $request->post('ad_id', 0);
        $h5code = $request->post('h5code', '');
        $type = $request->post('type', 0);
        $tmpid = $request->post('id', 0);
        $res = IndexService::adRead($ad_id, $h5code, $type, $tmpid);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //到小程序
    public function toxcx(Request $request)
    {
        $h5code = $request->post('h5code', '');
    }
}